#include <bits/stdc++.h>
using namespace std;
int f[31];

void solve() {
    int n, k;
    cin >> n >> k;
    if(k > 30) {
        cout << "0\n";
        return;
    }
    int ans = 0;
    int a = f[k - 1], b = f[k];
    for(int x = 0; x <= n / a; x++) {
        if((n - (a * x)) % b == 0 && (n - (a * x)) / b >= x){
            ans++;
        } 
    }
    cout << ans << endl;
}

int main() {
    f[1] = 0, f[2] = 1;
    for(int i = 3; i <= 30; i++) {
        f[i] = f[i - 1] + f[i - 2];
    }
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}
